using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using buildingLib.Prepare;
namespace _dmis.prepare
{
    public partial class DoorInputDlg : Form
    {
        public DoorInputDlg()
        {
            InitializeComponent();
        }

        private void DoorInputDlg_Load(object sender, EventArgs e)
        {
            projectListBindingSource.DataSource = ProjectList.GetProjects();
            checkLst.DisplayMember = "Name";
            checkLst.ValueMember = "ID";
        }

        private void projectListComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            checkLst.Items.Clear();
            if (this.projectListComboBox.SelectedValue != null)
            {
                Floors floors = Floors.GetFloors((Guid)this.projectListComboBox.SelectedValue);
                foreach (FloorItem f in floors)
                {
                    checkLst.Items.Add(f);
                }
            }

        }

        private void btn_Save_Click(object sender, EventArgs e)
        {
            int itemcount = checkLst.Items.Count;
            double ratio = double.Parse(txt_ratio.Text);
            double pureArea = double.Parse(txt_pureArea.Text);
            double deckArea = double.Parse(txt_deckArea.Text);
            double pubArea = ratio * pureArea;
            double totalArea = pubArea + pureArea;
            Guid buildingID = (Guid)this.projectListComboBox.SelectedValue;

            for (int i = 0; i < itemcount; ++i)
            {
                if (checkLst.GetItemChecked(i))
                {
                    FloorItem floor = (FloorItem) checkLst.Items[i];
                    DoorItem.BatchInsertDoor(floor.Name + this.txt_doorName.Text,
                        totalArea, pureArea, deckArea, pubArea,buildingID,floor.ID);
                }
            }
        }
    }
}